// $('.ljzc1').click(function(){
//     console.log(123);
// });

var zz = /^1[3|4|5|7|8]\d{9}$/;
var zzsjh = document.querySelector('.zzsjh');
var phonezi = document.querySelector('.phonezi');
zzsjh.onblur = function () {
    if (zz.test(this.value)) {
        phonezi.style.color = "green";
        phonezi.innerText = "输入正确！";
        return true
    } else {
        phonezi.style.color = "red";
        phonezi.innerText = "手机号码不是一个有效号码";
        return false
    }
}

var aodir7 = document.getElementsByClassName("aodir7")[0];
var mm1 = document.getElementsByClassName("mm1")[0];
var zx1 = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15}$/
aodir7.onblur = function () {
    if (zx1.test(this.value)) {
        mm1.style.color = "green";
        mm1.innerText = "输入正确！";
        return true

    } else {
        mm1.style.color = "red";
        mm1.innerText = "8-16位且必须包含大小写字母和数字的组合";
        return false
    }
}

var aodi = document.getElementsByClassName("aodi")[0];
var qrmm = document.getElementsByClassName("qrmm")[0];
var zz1 = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,15}$/
aodi.onblur = function () {
    if (zz1.test(this.value)) {
        qrmm.style.color = "green";
        qrmm.innerText = "输入正确！";
        return true

    } else if (aodir7.value != this.value && this.value != '') {
        qrmm.style.color = "red";
        qrmm.innerText = "两次输入密码不一致";
        return false
    } else if (this.value == '') {
        qrmm.style.color = "red";
        qrmm.innerText = "8-16位且必须包含大小写字母和数字的组合";
        return false
    }
}
   
// if (location.search) {
//     var zx = location.search.slice(1).split("&");
//     for (var i = 0; i < zx.length; i++) {
//         var text = zx[i].split("=");
//         //   console.log(text);
//         localStorage.setItem(text[0], text[1]);
//     }

//     location.href = "./register.html";
// };

// 点击已有账号
$('.tz').click(function () {
    location.href = "./login.html";
})

$(function(){
    code_draw()
  })
// 点击验证码 刷新验证码
$("#canvas").on('click', function () {
    code_draw();
})
    
// 点击立即注册
$("#submit").on('click', function () {
    // 验证手机号是否通过
    if (!zzsjh.onblur()) return
   
    // 验证码是否通过
    // 将输入的内容转为大写，可通过这步进行大小写验证
    var val = $(".photo").val().toLowerCase();
   
    var tpyzm1 = document.querySelector('.tpyzm1');
    // 获取生成验证码值
    var num = $('#canvas').attr('data-code');
    
    if (val == '') {
        tpyzm1.style.color = "red";
        tpyzm1.innerText = "请输入验证码";
        return
    } else if (val == num) {
        tpyzm1.style.color = "green";
        tpyzm1.innerText = "输入正确！";

    } else {
        tpyzm1.style.color = "red";
        tpyzm1.innerText = "验证码错误！请重新输入";
        return
    }


    // 验证密码是否通过
    if (!aodir7.onblur()) return
    // 验证确认密码是否通过
    if (!aodi.onblur()) return
    
    // localStorage.setItem(zzsjh.name,zzsjh.value);
    // localStorage.setItem(aodir7.name,aodir7.value);
     

    // 缓存多个账号
    // var accout=zzsjh.value;
    // var passw=aodir7.value
    // var arr=[];
    // if(localStorage.getItem('accoutDate')){
    //     arr=JSON.parse(localStorage.getItem('accoutDate'));
    // }
    // var obj={
    //     name:accout,
    //     pass:passw,
    // };
   
    // arr.push(obj);
    // localStorage.setItem('accoutDate',JSON.stringify(arr))


    // 缓存一个账号

    localStorage.setItem(zzsjh.name,zzsjh.value)
    localStorage.setItem(aodir7.name,aodir7.value)
    // 全部验证通过后，跳转
    location.href = "./login.html";
})
// 验证码方法
function code_draw() {
    var canvas_width = $('#canvas').width();
    var canvas_height = $('#canvas').height();
    var canvas = document.getElementById("canvas"); //获取到canvas的对象，演员
    var context = canvas.getContext("2d"); //获取到canvas画图的环境，演员表演的舞台
    canvas.width = canvas_width;
    canvas.height = canvas_height;
    var sCode = "A,B,C,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,W,X,Y,Z,1,2,3,4,5,6,7,8,9,0"; //取值范围
    var aCode = sCode.split(",");
    var aLength = aCode.length; //获取到数组的长度
    var value = [];
    for (var i = 0; i <= 3; i++) {
        var j = Math.floor(Math.random() * aLength); //获取到随机的索引值
        var deg = Math.random() * 30 * Math.PI / 180; //产生0~30之间的随机弧度
        var txt = aCode[j]; //得到随机的一个内容
        value[i] = txt.toLowerCase();
        var x = 10 + i * 20; //文字在canvas上的x坐标
        var y = 20 + Math.random() * 8; //文字在canvas上的y坐标
        context.font = "bold 23px 微软雅黑";

        context.translate(x, y);
        context.rotate(deg);

        context.fillStyle = code_randomColor();
        context.fillText(txt, 0, 0);

        context.rotate(-deg);
        context.translate(-x, -y);
    }
    // 将生成的值以属性的方法添加到元素
    value = value.join("");
    $('#canvas').attr('data-code', value)
    //验证码上显示线条
    for (var i = 0; i <= 5; i++) {
        context.strokeStyle = code_randomColor();
        context.beginPath();
        context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height);
        context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height);
        context.stroke();
    }
    //验证码上显示小点
    for (var i = 0; i <= 30; i++) {
        context.strokeStyle = code_randomColor();
        context.beginPath();
        var x = Math.random() * canvas_width;
        var y = Math.random() * canvas_height;
        context.moveTo(x, y);
        context.lineTo(x + 1, y + 1);
        context.stroke();
    }
}

function code_randomColor() { //得到随机的颜色值
    var r = Math.floor(Math.random() * 256);
    var g = Math.floor(Math.random() * 256);
    var b = Math.floor(Math.random() * 256);
    return "rgb(" + r + "," + g + "," + b + ")";
}

